home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / dkbuts.zip / IP2DKB.C < prev    next >
C/C++ Source or Header  |  1991-05-16  |  3KB  |  164 lines

  1. /*
  2.  
  3.  
  4. IP2DKB - 1.00  01/05/90  FPW2
  5.          1.10  05/07/90  AAC
  6.  
  7.          Do what you want with this, but leave this comment, my name,  and
  8.          copyright intact.
  9.  
  10.          DigiView IP format for color is basically the red, green, and blue
  11.          arrays (left to right, top to bottom) back to back with a 12 byte
  12.          trailer ($8000 $8000 $8000 $8000 $8000 $8000).  Since DigiView only
  13.          digitizes to 2 million levels, raw data from the digitizer itself
  14.          will have the LSB set to zero.
  15.  
  16.  
  17.    I can be reached on a few Denver Amiga BBS's, at fweed@nyx.cs.du.edu and
  18. uunet!isis!nyx!ufweed!fweed on UseNet, and at the following address:
  19.  
  20.               Frank P. Weed II
  21.               P.O. Box 28184 #16
  22.               Lakewood, CO  80228
  23.  
  24.  
  25.          Version 1.10 - Modified to semi-ANSI "C" for greater portability.
  26.  
  27.               Aaron A. Collins
  28. */
  29.  
  30. #include <stdio.h>
  31. #include <stdlib.h>
  32.  
  33.  
  34. /* Functions Prototypes */
  35. void Title(void);
  36. void ShowUsage(void);
  37. void CleanUp(int);
  38. void Validate(void);
  39. void Convert(void);
  40.  
  41. #ifndef FALSE
  42. #define FALSE    0
  43. #endif
  44.  
  45. #ifndef TRUE
  46. #define TRUE    !FALSE
  47. #endif
  48.  
  49. FILE *input, *output;
  50. unsigned short lines, width;
  51. int filepos, position;
  52. int checks = FALSE;
  53. char *IPBuf = NULL;
  54.  
  55. void Title()
  56. {
  57.     printf("\033[2;33mIP2DKB\033[0m - Version 1.10\n");
  58.     printf("\033[2;32mCopyright (c) 1991 Frank P. Weed II\n\033[0m");
  59. }
  60.  
  61. void ShowUsage()
  62. {
  63.     printf("\n");
  64.     printf("  Usage: \033[2;33mIP2DKB\033[0m <infile> <outfile>\n");
  65.     printf("\n");
  66.     exit(5);
  67. }
  68.  
  69. void CleanUp(n)
  70. int n;
  71. {
  72.     if (IPBuf)
  73.         free(IPBuf);
  74.     fcloseall();
  75.     exit(n);
  76. }
  77.  
  78. void Validate()
  79. {
  80.     long    filelen;
  81.  
  82.     fseek(input, 0L, 2);
  83.     filelen = ftell(input);
  84.     if (((long)width * lines * 3 + 12) == filelen)
  85.         checks = TRUE;
  86.     if (!checks)
  87.         {
  88.         printf("Input didn't pass validation\n");
  89.         CleanUp(1);
  90.         }
  91.     rewind(input);
  92. }
  93.  
  94. void Convert()
  95. {
  96.     int w,h;
  97.     unsigned char Hi,Lo;
  98.     char *rptr,*gptr,*bptr;
  99.  
  100.     printf("Width and height? ");
  101.     scanf("%d %d", &w, &h);
  102.     width = w; lines = h;
  103.     Validate();
  104.     IPBuf = (char *)malloc(width*lines*3);
  105.     if (IPBuf == NULL)
  106.         {
  107.         printf("Couldn't grab enough memory\n");
  108.         CleanUp(5);
  109.         }
  110.     printf("Reading...");
  111.     fread(IPBuf, width*lines*3, 1, input);
  112.     printf("done\n");
  113.     Hi = (unsigned char)(width % 256);
  114.     fwrite(&Hi, 1, 1, output);
  115.     Lo = (unsigned char)(width / 256);
  116.     fwrite(&Lo, 1, 1, output);
  117.     Hi = (unsigned char)(lines % 256);
  118.     fwrite(&Hi, 1, 1, output);
  119.     Lo = (unsigned char)(lines / 256);
  120.     fwrite(&Lo, 1, 1, output);
  121.     rptr = IPBuf;
  122.     gptr = IPBuf + (width * lines);
  123.     bptr = IPBuf + (2 * width * lines);
  124.     for (filepos=0; (unsigned short) filepos < lines; filepos++)
  125.         {
  126.         Hi = (unsigned char)(filepos % 256);
  127.         Lo = (unsigned char)(filepos / 256);
  128.         printf("Writing line #%d\n\033[0F", filepos);
  129.         fwrite(&Hi, 1, 1, output);
  130.         fwrite(&Lo, 1, 1, output);
  131.         fwrite(rptr, 1, width, output);
  132.         fwrite(gptr, 1, width, output);
  133.         fwrite(bptr, 1, width, output);
  134.         rptr += width;
  135.         gptr += width;
  136.         bptr += width;
  137.         }
  138.     printf("\n");
  139. }
  140.  
  141. void main(argc,argv)
  142. int    argc;
  143. char    *argv[];
  144. {
  145.     Title();
  146.     if (argc != 3)
  147.         ShowUsage();
  148.     input = fopen(argv[1],"rb");
  149.     if (input == NULL)
  150.         {
  151.         printf("Can't find input file\n");
  152.         CleanUp(5);
  153.         }
  154.     output = fopen(argv[2],"wb");
  155.     if (output == NULL)
  156.         {
  157.         printf("Can't make output file\n");
  158.         CleanUp(5);
  159.         }
  160.     Convert();
  161.     printf("Finished\n");
  162.     CleanUp(0);
  163. }
  164.